from radarssd_kv import *
import time

if __name__ == "__main__":
    kv_fd = open_mongodb()

    #先清空数据库
    clear_mongodb(kv_fd)

    #随机生成一系列信号，测试数据库写入性能
    start_time = time.time()
    test_time = 8*1000*1000
    #test_time = 1 * 44738560
    line_count = 0

    signal_list = []
    for i in range(test_time):
        signal_list.append(convert_dict(i, i+1, i+2))

        line_count += 1
        if(line_count % 20480 == 0):
            insert_mongodb(kv_fd, signal_list)
            signal_list.clear()
            print("inserted %d lines"%line_count)

    end_time = time.time()
    total_us = round(end_time-start_time,8)*1000000
    print("Insert",line_count,"signals")
    print("Total",total_us/1000000,"s, average",total_us/line_count,"us/signal")